package org.example.wx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.common.utils.ResponseUtil;
import org.example.db.entity.FootPrint;
import org.example.db.entity.Goods;
import org.example.db.mapper.GoodsMapper;
import org.example.wx.dto.FootprintGoodsDto;
import org.example.wx.service.WxFootPrintService;
import org.example.wx.service.WxGoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "足迹")
@RequestMapping("/wx/footprint")
public class WxFootPrintController {

    WxFootPrintService wxFootPrintService;
    GoodsMapper goodsMapper;

    public WxFootPrintController(WxFootPrintService wxFootPrintService, GoodsMapper goodsMapper) {
        this.wxFootPrintService = wxFootPrintService;
        this.goodsMapper = goodsMapper;
    }

    @GetMapping("/list")
    @ApiOperation("足迹列表")
    public Object list(){

        List<FootPrint> list = wxFootPrintService.list();
        ArrayList<FootprintGoodsDto> footprintGoodsDtoArrayList = new ArrayList<>();
        for(FootPrint footPrint: list){
            Goods goods = goodsMapper.selectById(footPrint.getGoodsId());
            footprintGoodsDtoArrayList.add(
                    new FootprintGoodsDto(goods.getId(), goods.getName(), goods.getPictureUrl(), footPrint.getUpdateTime(), goods.getRetailPrice()));

        }

        return ResponseUtil.ok(footprintGoodsDtoArrayList);
    }
}
